# 校验必填字段
from sqlalchemy import BOOLEAN


def caseRequiredAll(columns):
    """
    获取所有必填字段
    :param columns: 字段列表
    :return:
    """
    dataList = []
    for itm in columns:
        if itm.nullable == False and itm.autoincrement != True:
            dataList.append({"filed":itm.name,"name":itm.doc,"primaryKey":itm.primary_key})
        # print(itm.nullable,itm.name,itm.autoincrement,itm.type,itm.type.python_type)
    return dataList

def caseRequiredExist(parameter,columns,type_z="post"):
    """

    :param parameter: 所有参数
    :param columns: 所有字段
    :param type_z: 请求类型新增或者修改
    :return:
    """
    if type_z=="put":
        return None,None
    # 获取所有必填的参数
    dataList = caseRequiredAll(columns)
    parameterKeys = parameter.keys()
    for itm in dataList:
        # 如果是修改那么主键参数必填跳过
        if itm['primaryKey'] == True:
            continue
        if itm['filed'] not in parameterKeys:
            name = ""
            if itm['name'] != None:
                name = ",描述:" + itm['name'] + "不存在"
            return None,"参数:" + itm['filed'] + name
    return None,None